package com.example.dicos.controller;


import com.example.dicos.config.CommonResult;
import com.example.dicos.entity.dot.WxRolePermissionRelationDto;
import com.example.dicos.service.WxPermissionService;
import com.example.dicos.service.WxRolePermissionRelationService;
import com.example.dicos.service.WxUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 后台用户角色和权限关系表 前端控制器
 * </p>
 *
 * @author 开发者
 * @since 2022-07-11
 */
@Api(tags = "权限模块")
@RestController
@RequestMapping("/wxRolePermissionRelation")
public class WxRolePermissionRelationController extends BaseController {

    @Autowired
    private WxRolePermissionRelationService wxRolePermissionRelationService;

    @Autowired
    private WxPermissionService wxPermissionService;

    @Autowired
    private WxUserService wxUserService;

    @ApiOperation("权限列表查询")
    @GetMapping("/queryWxPermissionList")
    public CommonResult queryWxPermissionList() {

        return CommonResult.success(wxPermissionService.queryWxPermissionList());

    }

    @ApiOperation("角色分配权限")
    @PostMapping("/addWxRolePermissionRelation")
    public CommonResult addWxRolePermissionRelation(@RequestBody WxRolePermissionRelationDto wxRolePermissionRelationDto) {

        try {
            return CommonResult.success(wxRolePermissionRelationService.addWxRolePermissionRelation(wxRolePermissionRelationDto));
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @ApiOperation("角色id查询权限")
    @GetMapping("/queryWxPermissionVoList")
    public CommonResult queryWxPermissionVoList(@RequestParam("roleId") Long roleId) {

        return CommonResult.success(wxRolePermissionRelationService.queryWxPermissionVoList(roleId));
    }

    @ApiOperation("当前用户的权限列表 <token获取id>")
    @GetMapping("/userRole/permissionUserById")
    public CommonResult permissionUserById() {

        return CommonResult.success(wxUserService.permissionUserById(super.getUserById()));
    }


}

